<?php
namespace app\admin\logic;

use app\model\Machine;

class MachineLogic
{
    public function getPull(array $param)    
    {
        $machineModel = new Machine();
        $query = $machineModel->field('id,machine_code')
            ->where('delete_time', $machineModel::IS_DELETE_NO);

        if ($param['machine_code']) {
            $query->where('machine_code', $param['machine_code']);
        }

        return $query->order('id', 'desc')
            ->paginate([
                'list_rows' => $param['page_size'],
                'page' => $param['page'],
            ])
            ->toArray();
    }

    /**
     * @Description 列表
     * @author: zj
     * @param array $param
     * @time 2024/04/01 10:54:04
     * @return mixed
     */
    public function getList(array $param)
    {
        $machineModel = new Machine();
        $query = $machineModel->alias('m')
            ->join('factory f','f.id = m.factory_id','left')
            ->field('m.id,m.machine_code,m.factory_id,f.name as factory,m.now_version_id,m.target_version_id,m.force,m.status,m.create_time')
            ->where('m.delete_time', $machineModel::IS_DELETE_NO);
        if ($param['machine_code']) {
            $query->where('m.machine_code','like','%'.trim($param['machine_code']).'%');
        }
        if ($param['status']) {
            $query->where('m.status',$param['status']);
        }

        return $query->order('id DESC')
            ->paginate([
                'list_rows' => $param['page_size'],
                'page' => $param['page']
            ])
            ->toArray();
    }

}
